import { fileURLToPath, URL } from 'node:url';

import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  console.log('command: ', command);
  console.log('TITLE: ', env.VITE_APP_TITLE);
  console.log('ENV: ', env.VITE_ENV);
  return {
    plugins: [vue()],
    base: './',
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    build: {
      //设置输出目录
      outDir: '../cas-general-backend/src/main/resources/static/',
    },
    server: {
      //设置后端代理
      proxy: {
        '/api': {
          target: env.VITE_API_URL,
          changeOrigin: true, // 允许跨域
          rewrite: path => path.replace(/^\/api/, ''), // 将 /api 替换为空字符串
        },
      },
    },
  };
});
